const models = require("../models/index.js");
const Type = models.Type;
const ApiError = require("../error/ApiError.js");
class TypeController {
  async create(req, res) {
    const { name } = req.body;

    const type = await Type.create({ name });
    return res.json({ message: "Тип создан" });
  }
  async getAll(req, res) {
    const types = await Type.findAll();
    return res.json(types);
  }
  async getOne(req, res) {
    const { id } = req.params;
    const type = await Type.findOne({ where: { id } });
    return res.json(type);
  }
  async delete(req, res) {
    const { id } = req.params;
    const type = await Type.destroy({ where: { id } });
    return res.json({ message: "Тип удален" });
  }
}

module.exports = new TypeController();
